package serverside;

import java.sql.SQLException;
import java.util.Scanner;
import javax.swing.JOptionPane;

public class BalanceInquiry extends Transaction {
    private Scanner input;

    public BalanceInquiry(int _cardID, BankDatabase atmBankDatabase, Screen atmScreen) {
        super(_cardID, atmBankDatabase, atmScreen);
        input = new Scanner(System.in);
    }

    @Override
    public void execute() {
        try {
            System.out.println("Transaction::BalanceInquiry");
            BankDatabase bankDatabase = getBankDatabase();
            Screen screen = getScreen();

            screen.sendDataToClient("You can query.");
            String result = bankDatabase.Balancing_query(getCardID());
            System.out.println("Transaction::BalanceInquiry result: " + result +
                    "\n");
            screen.sendDataToClient(result);
        } catch (SQLException ex) {
            System.out.println("An error occured in performing BalanceInquiry releated to database");
            System.out.print("If you want to view error send 1 or 0 otherwise");
            if (input.nextInt() == 1) {
                JOptionPane.showMessageDialog(null, "Error", ex.getMessage(), JOptionPane.ERROR_MESSAGE);
            }
        }
    }

}
